import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    category:[],
    active:0
  },
  mutations: {
    GET_CATEGORY(state,items){
      // console.log(11111,items)
      state.category = items
    },
    CHANGE_ACTIVE(state,index){
      state.active = index
    }
  },
  actions: {
    GET_CATEGORY(context){
      axios.get('http://api.kudesoft.cn/tdk/category ').then((res)=>{
        // console.log(res.data.data.data)
        res.data.data.data.forEach((ele)=>{
          ele.subcategories.forEach((item)=>{
            item.price = 19,
            item.count = 1
          })
        })
        context.commit('GET_CATEGORY',res.data.data.data)
      }).catch((error)=>{
        console.log(error)
      })
    },
    CHANGE_ACTIVE(context,index){
      context.commit('CHANGE_ACTIVE',index)
    }
  },
  modules: {
  }
})
